package com.cloud.pole.shop.controller;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cloud.pole.common.constant.CommonConstants;
import com.cloud.pole.common.exception.BaseException;
import com.cloud.pole.common.exception.ParamException;
import com.cloud.pole.common.msg.ApiRestResponse;
import com.cloud.pole.common.util.RegexUtils;
import com.cloud.pole.shop.model.vo.IndexVo;
import com.cloud.pole.shop.model.vo.goods.ShopGoodsPromotionByTypeVo;
import com.cloud.pole.shop.model.vo.goods.ShopGoodsPromotionVo;
import com.cloud.pole.shop.service.IndexService;
import com.github.pagehelper.PageInfo;

import lombok.extern.slf4j.Slf4j;

@Controller
@Slf4j
@RequestMapping("/front")
public class IndexController {
	@Autowired
	IndexService indexService;
	
	@ResponseBody
	@RequestMapping("/index")
    public ApiRestResponse<IndexVo> index(
    		@RequestHeader(defaultValue = "") String token, 
    		@RequestHeader(defaultValue = "1") String shopId){   	
    	try {
			return ApiRestResponse.success(CommonConstants.STATUS_OK_MESSAGE, indexService.getIndexData(token, Integer.valueOf(shopId)));
    	} catch (BaseException e) {
			return ApiRestResponse.fail(e.getStatus(), e.getMessage(), null);
		} catch (Exception e) {
			log.error(CommonConstants.STATUS_ERROR_MESSAGE + "{}", e.getMessage(), e);
			return ApiRestResponse.fail(CommonConstants.STATUS_ERROR_MESSAGE, null);
		}
    }
	
	@ResponseBody
	@RequestMapping("/getGoodsPromotion")
    public ApiRestResponse<List<ShopGoodsPromotionVo>> getGoodsPromotion(
    		@RequestHeader(name="token", defaultValue="") String token,
    		@RequestParam(name="componentId", defaultValue="1") String componentId){
    	try {
			return ApiRestResponse.success(CommonConstants.STATUS_OK_MESSAGE, indexService.getGoodsPromotion(token, Integer.valueOf(componentId)));
    	} catch (BaseException e) {
			return ApiRestResponse.fail(e.getStatus(), e.getMessage(), null);
		} catch (Exception e) {
			log.error(CommonConstants.STATUS_ERROR_MESSAGE + "{}", e.getMessage(), e);
			return ApiRestResponse.fail(CommonConstants.STATUS_ERROR_MESSAGE, null);
		}
    }
	
}
